package com.lvt.example.thinking.in.spring.questions.L21.aop.example03;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Service;

/**
 * desc：class
 *
 * @author LT
 * @date 2022/10/24
 */

@Aspect
@Service
@Slf4j
public class AspectService {

    @Before("execution(* com.lvt.example.thinking.in.spring.questions.L21.aop.example03.ElectricService.charge()) ")
    public void checkAuthority(JoinPoint pjp) throws Throwable {
        System.out.println("validating user authority");
        Thread.sleep(1000);
    }

    @Around("execution(* com.lvt.example.thinking.in.spring.questions.L21.aop.example03.ElectricService.charge()) ")
    public void recordPerformance(ProceedingJoinPoint pjp) throws Throwable {
        long start = System.currentTimeMillis();
        pjp.proceed();
        long end = System.currentTimeMillis();
        System.out.println("charge method time cost: " + (end - start));
    }
}